<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    const deepClone = function (obj) {
      const cache = new Map();
      function _deepclone(obj) {
        if (typeof obj !== "object" || obj === null) {
          return obj;
        }
        if (cache.has(obj)) {
          return cache.get(obj);
        }
        let result = Array.isArray(obj) ? [] : {};
        cache.set(obj, result);
        for (let key in obj) {
          result[key] = _deepclone(obj[key]);
        }
        return result;
      }
      return _deepclone(obj);
    };
    let o = {
      name: "你好",
      a: {
        age: 123,
      },
    };
    o.c = o;
    const newO = deepClone(o);
    newO.a.age = 567;
    // console.log(newO, "__-新对象");
    // console.log(o, "__-旧对象");
    // const c = { a: 1, b: 2, c: 3 };
  </script>
</html>
